package com.clip.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.clip.entity.ContactGroupMapping;

@Repository
public class ContactGroupMappingDAO extends BasicDao  {
    private static final Log log = LogFactory.getLog(ContactGroupMappingDAO.class);

    
    public void save(ContactGroupMapping transientInstance) {
        log.debug("saving ContactGroupMapping instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(ContactGroupMapping persistentInstance) {
        log.debug("deleting ContactGroupMapping instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public ContactGroupMapping findById( java.lang.Integer id) {
        log.debug("getting ContactGroupMapping instance with id: " + id);
        try {
        	ContactGroupMapping instance = (ContactGroupMapping) getSession().get(ContactGroupMapping.class, id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
	public List findAll() {
		log.debug("finding all ContactGroupMapping instances");
		try {
			String queryString = "from ContactGroupMapping";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
    public ContactGroupMapping merge(ContactGroupMapping detachedInstance) {
        log.debug("merging ContactGroupMapping instance");
        try {
        	ContactGroupMapping result = (ContactGroupMapping) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(ContactGroupMapping instance) {
        log.debug("attaching dirty ContactGroupMapping instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(ContactGroupMapping instance) {
        log.debug("attaching clean ContactGroupMapping instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public List findByQuery(String query) {
		return getSession().createQuery(query).list();
	}
    
    public void updateByQuery(String query){
    	getSession().createQuery(query).executeUpdate();
    }
    public List<ContactGroupMapping> findByQuery(String string, Object... args) {
		Query queryobj=getSession().createQuery(string);
		if(args!=null&&args.length>0){
			for (int i = 0; i < args.length; i++) {
				queryobj.setParameter(i, args[i]);
			}
		}
		return queryobj.list();
	}
}